package com.hellobike.haxing.test.wms;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hellobike.haxing.common.util.DateUtils;
import com.hellobike.haxing.common.vo.Result;
import com.hellobike.haxing.modules.order.entity.Order;
import com.hellobike.haxing.modules.wms.entity.DeliveryOrderDetail;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

public class WmsLocationBD {
    public static void main1(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\bak.txt"));
        String line = null;
        int index = 0;
        while ((line = reader.readLine()) != null) {
            //INSERT INTO t_wms_sku_ext_temp (id,sku_id,loc_id,warehouse_id)VALUES();
            if (index > 2) {
                String[] arr = line.split("\\|");
//                System.out.println(Arrays.asList(arr));
                System.out.println("INSERT INTO t_wms_sku_ext_temp (id,sku_id,loc_id,warehouse_id)VALUES(" + arr[0].trim() + "," + arr[1].trim() + "," + arr[2].trim() + "," + arr[3].trim() + ");");

            }
            index++;
        }
    }

    public static void main2(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\detail"));
        String line = reader.readLine();
        Result results = JSON.parseObject(line, Result.class);
        System.out.println(results);
        JSONObject records = (JSONObject) results.getResult();
        JSONArray jsonArray = records.getJSONArray("records");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if (jsonObject.getIntValue("isAsync") == 0 && jsonObject.getInteger("status") == 3) {
                Date successTime = jsonObject.getDate("successTime");
                System.out.print(jsonObject.getString("billNo") + " ");

                if (successTime != null) {
                    System.out.println(DateUtils.formatDate(successTime, "yyyy-MM-dd HH:mm:ss"));
                } else {
                    System.out.println("no date");
                }
            }
        }

    }
    static String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1ODMyNDM1MzcsInVzZXJuYW1lIjoiYWRtaW4ifQ.uZJn60vgf5kQUcje6ivq6fp2mmJoxExY3Gx46swA6Is";
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\order-relation"));
        String line = reader.readLine();
        JSONArray jsonArray = JSON.parseObject(line).getJSONObject("result").getJSONArray("records");
        Map<String, List<String>> map = new HashMap<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            String userOrderId = object.getString("userOrderId");
            String deliveryOrderId = object.getString("deliveryOrderId");
            System.out.println("do  "+deliveryOrderId);
            System.out.println(object.getString("id"));
            if (!map.containsKey(deliveryOrderId)) {
                map.put(deliveryOrderId, new ArrayList<>());
            }
            map.get(deliveryOrderId).add(userOrderId);
        }
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.add("x-access-token", token);
        HttpEntity<String> requestEntity = new HttpEntity<String>(null, requestHeaders);
        RestTemplate template = new RestTemplate();

//        Map<String, List<String>> map2 = new HashMap<>();
//
//        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
//            ResponseEntity<String> response = template.exchange("https://backend.hzhaxing.com/haxing-boot/wms/deliveryOrderHeader/queryById?id="+entry.getKey(), HttpMethod.GET, requestEntity, String.class);
//            String sttr = response.getBody();
//            String string1 = JSON.parseObject(sttr).getJSONObject("result").getString("orderCode");
//            map2.put(string1,new ArrayList<>());
//            for (String s1 : entry.getValue()) {
//                response = template.exchange("https://backend.hzhaxing.com/haxing-boot/order/order/queryById?id="+s1, HttpMethod.GET, requestEntity, String.class);
//                sttr = response.getBody();
//                String string = JSON.parseObject(sttr).getJSONObject("result").getString("billNo");
//                map2.get(string1).add(string);
//            }
//        }
//        for (Map.Entry<String, List<String>> entry : map2.entrySet()) {
//            System.out.println(entry.getKey());
//            System.out.println(entry.getValue());
//            System.out.println("=====================");
//        }
    }
}
